********************************************************************************
** 	TITLE: d3_recidivism_misconduct_by_time.do
**
**	PROJECT: IGNITE
** 
**  PURPOSE: Figure III: Misconduct and Recidivism Effects Over Time

********************************************************************************
		set sortseed 13

	use "$output_data/estimate.dta", replace

***************************************************************************
*Panel (b) Recidivism
***************************************************************************	
***** return_`j'm is defined to be 1[Ever rebooked in j months after release]
mat R=J(20,3,.)

			//stay ignite_0 for Recidivism
	cap drop stay
	gen stay = stay_rec
	cap drop ignite_0
	gen ignite_0 = ignite_0_rec
			
forvalues j=1/12{
	ivreghdfe return_`j'm ( ignite_0 stay  = i.D_remove_any i.interact_proxy_any )  ///
							D_ignite_proxy $auxiliary_control ///
							if return_`j'm>=0,  ///
							cluster(inmate) ///
	a($design_control)
							
	mat R[`j',1] = _b[ignite_0]					
	mat R[`j',2] = _se[ignite_0]		
	mat R[`j',3] = `j'
}

mat li R
preserve

svmat R
keep R1-R3
keep if !mi(R1)
ren (R1 R2 R3) (c se t)
gen ul = c+1.96*se
gen ll = c-1.96*se

 tw (line ul t, lp(dash) lc(gs8) lwidth(medium)) ///
 	(line ll t,  lp(dash) lc(gs8) lwidth(medium)) ///
 	(line c t, lc(gs8) lwidth(medium)) ///
 	(scatter c t, mc(gs8) msymbol(O)) ///
 	, ///
 	yline(0, lc(black) ) ylab(-.2(.1).1) ///
 	xsc(r(1 12)) xlab(3(3)12) ///
 	legend(off) xtitle("Months since release") ///
 	ytitle("Recidivism") ysize(4) xsize(5.5)

 gr export "$figures/figure3b_recidivism_by_time.pdf", replace
 gr export "$figures/figure3b_recidivism_by_time.tif",  width(1650) height(1200) replace //300 dpi

restore

***************************************************************************
*Panel (a) Misconduct
***************************************************************************	
*** D_maj_`j'week is defined to be 1[Ever major misconduct in j weeks since booking]

mat R=J(20,3,.)

			//stay ignite_0 for misconduct
	cap drop stay
	gen stay = stay_misc
	cap drop ignite_0
	gen ignite_0 = ignite_0_misc

forvalues j=1/8{
	ivreghdfe D_maj_`j'week ( ignite_0 stay  = i.D_remove_any i.interact_proxy_any )  ///
							D_ignite_proxy $auxiliary_control ///
							if D_maj_`j'week>=0,  ///
							cluster(inmate) ///
	a($design_control)
							
	mat R[`j',1] = _b[ignite_0]					
	mat R[`j',2] = _se[ignite_0]		
	mat R[`j',3] = `j'
}

mat li R
preserve

svmat R
keep R1-R3
keep if !mi(R1)
ren (R1 R2 R3) (c se t)
gen ul = c+1.96*se
gen ll = c-1.96*se


tw (line ul t, lp(dash) lc(gs8) lwidth(medium)) ///
	(line ll t,  lp(dash) lc(gs8) lwidth(medium)) ///
	(line c t, lc(gs8) lwidth(medium) ) ///
	(scatter c t, mc(gs8) msymbol(O) ) ///
	, ///
	yline(0, lc(black) ) ylab(-.2(.1).1) ///
	xsc(r(1 8)) xlab(1(1)8) ///
	legend(off) xtitle("Weeks since booking") ///
	ytitle("Major misconduct") ysize(4) xsize(5.5)

gr export "$figures/figure3a_misconduct_by_time.pdf", replace
gr export "$figures/figure3a_misconduct_by_time.tif",  width(1650) height(1200) replace //300 dpi

